/*
 * Copyright 2010 David de Mingo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.shalma.internal;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.TreeMap;

import org.shalma.Service;
import org.shalma.model.Entity;

// TODO move to EntityManager(client)
public class EntityManager implements Service {

	private TreeMap<String, EntityInfo> entities;

	private EntityManager() {

		entities = new TreeMap<String, EntityInfo>();

		for (Class<? extends Entity> entity : EntityRegistry.instance
				.getEntities()) {

			final EntityInfo info = new EntityInfo(entity);
			entities.put(info.getUrl(), info);
		}
	}

	public static String getName(Class<?> clazz) {
		return clazz.getSimpleName();
	}

	public static String getName(Field field) {
		return field.getName();
	}

	public EntityInfo getEntityInfo(String url) {

		return entities.get(url);
	}

	public Collection<EntityInfo> getEntityInfos() {
		return entities.values();
	}
}
